package cn.bgs.controller;

import cn.bgs.pojo.Student;
import cn.bgs.service.StudentGradeRelationService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/grastu")
public class StudentGradeRelationController {


    @Autowired
    private StudentGradeRelationService studentGradeRelationService;






    //添加学生
    @RequestMapping("/addGraStu")
    @ResponseBody
    public Map<String,Object> addGraStu(@RequestBody String addGraStu){
        JSONObject jsonObject = JSONObject.parseObject(addGraStu);
        String stuId = jsonObject.getString("stuId");
        String gradeId = jsonObject.getString("gradeId");
        String gradeName = jsonObject.getString("gradeName");

        Map<String,Object> mm = new HashMap<>();
        try{
            int i = studentGradeRelationService.addGraStu(stuId, gradeId, gradeName);
            mm.put("code",0000);
            mm.put("msg","添加成功");

        }catch(PageException e){
            mm.put("code",9999);
            mm.put("msg","添加失败");
        }

        return mm;
    }

}
